package web.fabrimind.bdm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.bdm.domain.ProductionLine;
import web.fabrimind.bdm.service.IProductionLineService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 生产线管理Controller
 * 
 * @author 智慧
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/bdm/line")
public class ProductionLineController extends BaseController
{
    @Autowired
    private IProductionLineService productionLineService;

    /**
     * 查询生产线管理列表
     */
    @PreAuthorize("@ss.hasPermi('bdm:line:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionLine productionLine)
    {
        startPage();
        List<ProductionLine> list = productionLineService.selectProductionLineList(productionLine);
        return getDataTable(list);
    }

    /**
     * 导出生产线管理列表
     */
    @PreAuthorize("@ss.hasPermi('bdm:line:export')")
    @Log(title = "生产线管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionLine productionLine)
    {
        List<ProductionLine> list = productionLineService.selectProductionLineList(productionLine);
        ExcelUtil<ProductionLine> util = new ExcelUtil<ProductionLine>(ProductionLine.class);
        util.exportExcel(response, list, "生产线管理数据");
    }

    /**
     * 获取生产线管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bdm:line:query')")
    @GetMapping(value = "/{lineId}")
    public AjaxResult getInfo(@PathVariable("lineId") Long lineId)
    {
        return success(productionLineService.selectProductionLineByLineId(lineId));
    }

    /**
     * 新增生产线管理
     */
    @PreAuthorize("@ss.hasPermi('bdm:line:add')")
    @Log(title = "生产线管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionLine productionLine)
    {
        return toAjax(productionLineService.insertProductionLine(productionLine));
    }

    /**
     * 修改生产线管理
     */
    @PreAuthorize("@ss.hasPermi('bdm:line:edit')")
    @Log(title = "生产线管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionLine productionLine)
    {
        return toAjax(productionLineService.updateProductionLine(productionLine));
    }

    /**
     * 删除生产线管理
     */
    @PreAuthorize("@ss.hasPermi('bdm:line:remove')")
    @Log(title = "生产线管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lineIds}")
    public AjaxResult remove(@PathVariable Long[] lineIds)
    {
        return toAjax(productionLineService.deleteProductionLineByLineIds(lineIds));
    }


    /**
     * 查询所属车间列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('bdm:workshop:list')")
    @GetMapping("/workshop/getlist")
    public AjaxResult getWorkShopList(ProductionLine productionLine) {
        List<ProductionLine> workshopList = productionLineService.selectWorkShopList(productionLine);
        return AjaxResult.success(workshopList);
    }



}
